//
// Created by wangwanlong on 2024/6/19.
//
//测试缩合
#include <vector>
#include <fstream>
#include <sstream>
#include "graph.h"
#include "macros.h"
#include "partition/coarsen/mem_coarsener.h"
#include "graph_io.h"
#include "partitioner.h"

using namespace std;

void readGraph(const std::string &filename, int &nodeNum, int &edgeNum, vector<vector<int>> &adj_list) {
  std::ifstream file(filename);
  if (!file.is_open()) {
    LOG << filename;
    ERROREXIT("file not Found!");
  }
  std::string line;
  std::getline(file, line);
  std::stringstream ss(line);
  ss >> nodeNum >> edgeNum;
  LOG<<nodeNum<<edgeNum;

  adj_list.resize(nodeNum);
  int ans = 0;
  for (int i = 0; i < nodeNum; ++i) {
    std::getline(file, line);
    std::stringstream ss(line);
    int v;
    while (ss >> v) {
      --v;
      adj_list[i].emplace_back(v);
    }

    ans += adj_list[i].size();

  }


  file.close();
  if(ans != edgeNum * 2)
    ERROREXIT("error!");

}
void testMemCoarsen(mcgpp::ds::GenericGraph& graph){
  //读取种子分区
  mcgpp::Partitioner partitioner(graph);
  partitioner.readPartitionFile();
  mcgpp::MemCoarnsener<> coarsener(graph);
  LOG << "begin mem contraction ";
  coarsener.coarsenImpl(40000);


  LOG << "begin mem uncontraction";
  mcgpp::SaRefiner saRefiner(graph);
  saRefiner.initializeImpl();
  coarsener.uncoarsenImpl();

  for(int i =0; i < graph._num_nodes;++i){
    if(graph.nodeIsEnabled(i) == false)
      ERROREXIT("state error!");
  }
  for(int i=0;i<graph._num_edges;++i){
    if(graph.edgeIsEnabled(i) == false)
      ERROREXIT("edge state error!");
  }

  //check
  graph.check();
  LOG<<"finish success!";
}

int main() {
  std::string file = "..\\instance\\wing.graph";
  int nodeNum, edgeNum;
  vector<vector<int>> adj_list;
  readGraph(file, nodeNum, edgeNum, adj_list);





}


